package com.qst.rongxiaotong.controller;

import com.qst.rongxiaotong.common.Result;
import com.qst.rongxiaotong.common.StatusCode;
import com.qst.rongxiaotong.pojo.Discuss;
import com.qst.rongxiaotong.service.DiscussService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "评论模块接口")
@RestController
@RequestMapping("/discuss")
@CrossOrigin
public class DiscussController {

    @Autowired
    DiscussService discussService;

    @ApiOperation(value = "查询评论信息")
    @GetMapping("/selectByKnowledge/{id}")
    public Result selectByKnowledge(@PathVariable("id")Integer id){
        List<Discuss> discusses = discussService.selectByKnowledgeId(id);
        Result result = new Result(true, StatusCode.OK, "查询成功", discusses);
        return result;
    }

    @ApiOperation(value = "添加评论信息")
    @GetMapping("/addByKnowledge/{id}/{content}")
    public Result addByKnowledge(@PathVariable("id")Integer id,@PathVariable("content")String content){

        Discuss discuss = new Discuss();
        discuss.setKnowledgeId(id).setContent(content).setCreateTime(new Date()).setOwnName("wyn3");
        discussService.add(discuss);
        Result result = new Result(true, StatusCode.OK, "添加成功", discuss);
        return result;

    }




}
